package com.ruoyi.energy.service.impl;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.energy.domain.DpEnergyQy;
import com.ruoyi.energy.mapper.DpEnergyQyMapper;
import com.ruoyi.energy.service.IDpEnergyQyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 企业能源汇总Service业务层处理
 *
 * @author cjie
 * @date 2022-12-04
 */
@Service
public class DpEnergyQyServiceImpl implements IDpEnergyQyService {
    @Autowired
    private DpEnergyQyMapper dpEnergyQyMapper;

    /**
     * 查询企业能源汇总
     *
     * @param id 企业能源汇总ID
     * @return 企业能源汇总
     */
    @Override
    public DpEnergyQy selectDpEnergyQyById(String id) {
        return dpEnergyQyMapper.selectDpEnergyQyById(id);
    }

    /**
     * 查询企业能源汇总列表
     *
     * @param dpEnergyQy 企业能源汇总
     * @return 企业能源汇总
     */
    @Override
    public List<DpEnergyQy> selectDpEnergyQyList(DpEnergyQy dpEnergyQy) {
        return dpEnergyQyMapper.selectDpEnergyQyList(dpEnergyQy);
    }

    /**
     * 新增企业能源汇总
     *
     * @param dpEnergyQy 企业能源汇总
     * @return 结果
     */
    @Override
    public int insertDpEnergyQy(DpEnergyQy dpEnergyQy) {
        return dpEnergyQyMapper.insertDpEnergyQy(dpEnergyQy);
    }

    /**
     * 修改企业能源汇总
     *
     * @param dpEnergyQy 企业能源汇总
     * @return 结果
     */
    @Override
    public int updateDpEnergyQy(DpEnergyQy dpEnergyQy) {
        return dpEnergyQyMapper.updateDpEnergyQy(dpEnergyQy);
    }

    /**
     * 批量删除企业能源汇总
     *
     * @param ids 需要删除的企业能源汇总ID
     * @return 结果
     */
    @Override
    public int deleteDpEnergyQyByIds(String[] ids) {
        return dpEnergyQyMapper.deleteDpEnergyQyByIds(ids);
    }

    /**
     * 删除企业能源汇总信息
     *
     * @param id 企业能源汇总ID
     * @return 结果
     */
    @Override
    public int deleteDpEnergyQyById(String id) {
        return dpEnergyQyMapper.deleteDpEnergyQyById(id);
    }

    @Override
    public List<DpEnergyQy> selectDpEnergyQyListPlus(DpEnergyQy dpEnergyQy) {
        return dpEnergyQyMapper.selectDpEnergyQyListPlus(dpEnergyQy);
    }

    @Override
    public Map<String,String> selectDpEnergyQyTrend(DpEnergyQy dpEnergyQy) {
        List<DpEnergyQy> dpEnergyQyList = dpEnergyQyMapper.selectDpEnergyQyTrend(dpEnergyQy);
        Map<String,String> results = new LinkedHashMap<>(dpEnergyQyList.size());
        if(dpEnergyQy.getMeterType().equals("水表")){
            for(int i = dpEnergyQyList.size()-1;i>=0;i--){
                results.put(DateUtil.month(dpEnergyQyList.get(i).getFeeCycle())+"",dpEnergyQyList.get(i).getWaterActualDosage().toString());
            }
        }else if(dpEnergyQy.getMeterType().equals("电表")){
            for(int i = dpEnergyQyList.size()-1;i>=0;i--){
                results.put(DateUtil.month(dpEnergyQyList.get(i).getFeeCycle())+"",dpEnergyQyList.get(i).getElActualDosage().toString());
            }
        }
        return results;
    }
}
